package com.trdcore.zyzkt.controller;


import com.trdcore.zyzkt.model.vod.Chapter;
import com.trdcore.zyzkt.resp.ResultData;
import com.trdcore.zyzkt.service.ChapterService;
import com.trdcore.zyzkt.vo.vod.ChapterVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Luffy
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/admin/vod/chapter")

@Tag(name = "章节")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;
    //大纲列表

    @Operation(summary = "大纲列表",description = "大纲列表")
    @GetMapping("/getNestedTreeList/{courseId}")
    public ResultData getTreeList(@PathVariable("courseId")Long courseId){
        List<ChapterVo> list=chapterService.getTreeList(courseId);
        return ResultData.success(list);
    }

    //添加章节
    @PostMapping("/save")
    @Operation(summary = "添加章节",description = "添加章节")
    public ResultData save(@RequestBody Chapter chapter){
        return ResultData.success(chapterService.save(chapter));
    }

    //根据Id查询
    @GetMapping("/get/{id}")
    @Operation(summary = "添加章节",description = "添加章节")
    public ResultData get(@PathVariable("id") Long id){
        Chapter chapter = chapterService.getById(id);
        return ResultData.success(chapter);
    }

    //修改
    @PostMapping("/update")
    @Operation(summary = "修改",description = "修改")
    public ResultData update(@RequestBody Chapter chapter){
        return ResultData.success(chapterService.updateById(chapter));
    }


    //删除章节
    @PostMapping("/remove/{id}")
    @Operation(summary = "删除章节",description = "删除章节")
    public ResultData remove(@PathVariable("id") Long id){
        return ResultData.success(chapterService.removeById(id));
    }



}

